var util = require('../../utils/util.js')
Page({
  data: {
    list: []
  },
  onTabClick: function(event){
    var d = event.currentTarget.dataset;
    console.log(d.index);
  },
  bindItemTap : function(event){
    var d = event.currentTarget.dataset;
    wx.navigateTo({
      url: '../list/list?id=' + d.id
    })
  },
  onContentTap : function(){
    wx.navigateTo({
      url: '../list/list'
    })
  },
  wrapDataToVo : function(list){
      var rows = [];
      var row;
      for(var i=0;i<list.length;i++){
        if(i % 3 == 0){
          row = {data:[]}; 
          rows.push(row);
        }
        row.data.push(list[i]);
      }
      return rows;
  },
  onLoad: function () {
    var that = this
    wx.request({
      url: 'http://localhost:8080/home/listBooks',
      success : function(res){
        var list = res.data;
        var rows = that.wrapDataToVo(list);
        console.log(rows);
        that.setData({list:rows});
      }
    });
  }
})
